package fr.greta.centreFormation.controller;

import java.io.IOException;
import java.sql.SQLException;
import java.util.ArrayList;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import fr.greta.centreFormation.bean.Log;
import fr.greta.centreFormation.dao.LogHome;

/**
 * Servlet implementation class ListerLog
 */
public class ListerLog extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public ListerLog() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doPost(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
	
		ArrayList<Log> lesLogs = new ArrayList<Log>();
		
		int nbConnexion = 0;
		
		try {
			// Selection tous les logs
			lesLogs = LogHome.selectAllLog();
			
			//Selection de tous les logs
			nbConnexion = LogHome.selectAllLogApres30J();
			
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		// Ajout en Attribut de tous les log
		request.setAttribute("lesLog", lesLogs);
		// Ajout en Attribut du nb de connexion.
		request.setAttribute("nbConnexion", nbConnexion);
		
		System.out.println(lesLogs);
		
		request.getRequestDispatcher("lesLogs.jsp").forward(request, response);
		
	}

}
